home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-21 | 5.9 KB | 266 lines | [TEXT/CWIE] |
- // =================================================================================
- // CThreadsApp.cp ©1996 Metrowerks Inc. All rights reserved.
- // =================================================================================
-
- #include <LGrowZone.h>
- #include <LString.h>
- #include <LThread.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PPobClasses.h>
- #include <UDesktop.h>
- #include <UDrawingState.h>
- #include <UEnvironment.h>
- #include <UMemoryMgr.h>
- #include <UReanimator.h>
- #include <URegistrar.h>
- #include <UThread.h>
- #include "LSingleLineCaption.h"
-
- #include "ThreadsConstants.h"
- #include "LThermometerPane.h"
- //#include "CProgressPane.h"
- #include "CThreadWindow.h"
-
- #include "CThreadsApp.h"
-
- #include "LProgressDialog.h"
- #include "LAnimateCursor.h"
-
- // =================================================================================
- // • Main Program
- // =================================================================================
-
- void
- main( void )
- {
- // Initialize the heap. Parameter is number
- // of master handle blocks to allocate.
- InitializeHeap( 4 );
-
- // Initialize the MacOS toolbox.
- UQDGlobals::InitializeToolbox( &qd );
-
- // Check for thread manager.
- if ( !UEnvironment::HasFeature( env_HasThreadsManager ) ) {
-
- ::StopAlert( rALRT_NoThreadManager, nil );
- ::ExitToShell();
- }
-
- // Install a GrowZone function to catch low memory situations.
- // Parameter is the size of the memory reserve in bytes.
- new LGrowZone( 20000 );
-
- // Create the application object and run it.
- CThreadsApp theApp;
- theApp.Run();
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CThreadsApp
- // ---------------------------------------------------------------------------------
-
- CThreadsApp::CThreadsApp()
- {
- // Setup the throw and signal actions.
- SetDebugThrow_( debugAction_Alert );
- SetDebugSignal_( debugAction_Alert );
-
- // Register PowerPlant class creator functions.
- RegisterAllPPClasses();
-
- // Register custom classes.
- URegistrar::RegisterClass( 'PrgP',
- LThermometerPane::CreateThermometerFromStream );
- URegistrar::RegisterClass( CThreadWindow::class_ID,
- CThreadWindow::CreateThreadWindowStream );
- URegistrar::RegisterClass( LSingleLineCaption::class_ID,
- LSingleLineCaption::CreateCaptionStream );
-
- // Create the main thread.
- new UMainThread;
-
- // Add a yield attachment.
- AddAttachment( new LYieldAttachment( -1 ) );
-
- // Set sleep time to a low value.
- SetSleepTime( 1 );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ~CThreadsApp
- // ---------------------------------------------------------------------------------
-
- CThreadsApp::~CThreadsApp()
- {
- }
-
-
- // ---------------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------------
-
- void
- CThreadsApp::StartUp()
- {
- ObeyCommand( 'nprg', nil );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------------
-
- Boolean
- CThreadsApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam )
- {
- Boolean cmdHandled = true;
-
- switch ( inCommand ) {
-
- case cmd_New:
- {
- Try_{
-
- // Make a new window.
- LWindow *theWindow;
- theWindow = LWindow::CreateWindow( rPPob_ThreadsWindow, this );
- ThrowIfNil_( theWindow );
-
- // Show the window.
- theWindow->Show();
-
- } Catch_( inErr ) {
-
- // Oops, couldn't create the window.
-
- } EndCatch_
- }
- break;
-
- //
- // test LProgressDialog
- //
- case 'nprg':
- {
- LProgressDialog progress("\pTimeless", this);
- LAnimateCursor cursor(256, 4);
-
- //
- // LProgressDialog starts life invisible
- // to avoid title flashing
- //
-
- progress.Show();
-
- UInt32 ticksAfterOne, ticksAfterTwo;
-
- progress.SetActionDescriptor("\pLet’s shock the monkey");
-
- //
- // generate picture of ronald reagan
- //
- progress.SetStepDescriptor("\pGenerating picture of nude Ronald Reagon…");
-
- ticksAfterOne = TickCount() + 50;
- ticksAfterTwo = TickCount() + 100;
-
- progress.SetTaskType(task_Indeterminate); // start with stripes
-
- while(ticksAfterOne > TickCount() &&
- !progress.IsStopClicked())
- {
- ProcessNextEvent();
- progress.CompletedThisMuch(ticksAfterTwo - TickCount());
- cursor.Set();
- }
-
- //
- // show it to the monkey
- //
- progress.SetStepDescriptor("\pShowing picture to the monkey…");
-
- ticksAfterTwo = TickCount() + 100;
- progress.SetTaskType(task_Measured); // switch to progress bar
-
- while(ticksAfterTwo > TickCount() &&
- !progress.IsStopClicked())
- {
- ProcessNextEvent();
- progress.CompletedThisMuch(ticksAfterTwo - TickCount());
- cursor.Set();
- }
-
- //
- // shore up PowerPlant's command hierarchy
- //
-
- LCommander::SwitchTarget(this);
-
- }
- break;
-
- default:
- {
- // Call inherited.
- cmdHandled = LApplication::ObeyCommand( inCommand, ioParam );
- }
- break;
-
- }
-
- return cmdHandled;
- }
-
- //
- // override adjustcursor -- this is necessary so InitCursor
- // won't be called while we're spinning the cursor
- //
-
- void CThreadsApp::AdjustCursor(const EventRecord &inMacEvent)
- {
- if(!LCursor::IsLocked())
- {
- LApplication::AdjustCursor(inMacEvent);
- }
- }
-
-
- // ---------------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------------
-
- void
- CThreadsApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName )
- {
- switch ( inCommand ) {
-
- case cmd_New:
- case 'nprg':
- {
- // Enable the new command.
- outEnabled = true;
- }
- break;
-
- default:
- {
- // Call inherited.
- LApplication::FindCommandStatus( inCommand,
- outEnabled, outUsesMark, outMark, outName );
- }
- break;
-
- }
- }
-